home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.9 KB | 429 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLCyPart.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- // Implementation of FW_OCyberPartExtension.
- // Redirects all methods into C callbacks provided by the client.
- //
- //========================================================================================
-
- #ifndef SOM_ODF_FW_OCyberPartExtension_xih
- #define ODF_FW_OCyberPartExtension_Class_Source
- #include <SLCyPart.xih>
- #endif
-
- //
- // Cyberdog
- //
-
- #ifndef SOM_CyberSession_xh
- #include <CyberSession.xh>
- #endif
-
- #ifndef SOM_ParameterSet_xh
- #include <ParameterSet.xh>
- #endif
-
- //
- // OpenDoc
- //
-
- #ifndef _MEMMGR_
- #include <MemMgr.h>
- #endif
-
- //========================================================================================
- // SOM Utilities
- //========================================================================================
- #pragma mark SOM Utilities
-
- /*
- Since we have a SOM interface, we have to make sure we don't try to
- throw any C++ exceptions out of here; we need to catch them and convert
- them into SOM exceptions.
- */
-
- static const char FW_kInvalidException[] = "Unknown Exception!";
-
- #define FW_SOM_CALLBACK_TRY \
- FW_TRY \
- {
-
- #define FW_SOM_CALLBACK_ENDTRY \
- } \
- FW_CATCH_BEGIN \
- FW_CATCH_REFERENCE(FW_XException, exception)\
- { \
- FW_SetException(ev, exception);\
- } \
- FW_CATCH_EVERYTHING() \
- { \
- FW_DEBUG_MESSAGE(FW_kInvalidException);\
- FW_SetEvError(ev, kODErrUndefined);\
- } \
- FW_CATCH_END
-
- /*
- We should not do anything if our base part has been removed (IsValid).
- Also make sure we have a callback struct and callback.
-
- NOTE: Some preprocessors do not accept null parameters. In that case we
- pass in a "(void)" as the first parameter. [sfu]
- */
-
- #define SAFECALL(RESULT,METHOD,PARAMETERS) \
- if (somSelf->IsValid(ev) \
- && somThis->fCallbacks \
- && somThis->fCallbacks->METHOD) \
- (RESULT (somThis->fCallbacks->METHOD) PARAMETERS, SOMCHKEXCEPT)
-
- #pragma mark -
- //========================================================================================
- // Class ODF_FW_OCyberPartExtension (SOM)
- //========================================================================================
- #pragma mark Class ODF_FW_OCyberPartExtension (SOM)
-
- /*
- SOM Subclass of CyberPartExtension
-
- These methods generally call C methods which have been exported from a
- client. These C methods must not throw C++ exceptions. Most of these
- methods here don't call C++ methods or somSelf methods and so do not
- need to guard against exceptions being thrown via SOMCHKEXCEPT.
- */
-
-
- //-----------------------------------------------------------------------------
- // SLCyPart::Release
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK SLCyPart__Release (ODF_FW_OCyberPartExtension *somSelf, Environment *ev)
- {
- FW_SOM_CALLBACK_TRY
-
- ODBoolean isOwned = somSelf->IsValid (ev);
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_Release(somSelf,ev);
-
- if (!isOwned && somSelf->GetRefCount(ev) == 0)
- delete somSelf;
-
- FW_SOM_CALLBACK_ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::OpenCyberItem
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK
- SLCyPart__OpenCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item, ODPart* openerPart, ParameterSet* openParams)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- FW_SOM_CALLBACK_TRY
-
- // The base class implements the default behavior, which is to call
- // somSelf->SetCyberItem(item), and then to either tell the openerPart
- // (if it is not kODNULL) to open the associated base part, or to tell
- // the base part to open itself.
- // Developers may call inherited.
-
- // mlanett 4/18/96 In order to make it possible for developer to call inherited, the
- // call to ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem has been
- // moved to DefaultOpenCyberItem. FW_CCyberdogHelper calls this by default. Developers
- // can override, and by calling inherited from C++, will get the actual inherited SOM
- // functionality. See FW_CCyberdogHelper::HandleOpenCyberItem.
- ODBoolean callInherited = false;
-
- SAFECALL((void),openCyberItem,(ev, somThis->fCallbacks, item, openerPart, openParams));
-
- if (callInherited)
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem(somSelf,ev,item,openerPart,openParams);
-
- FW_SOM_CALLBACK_ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::SetCyberItem
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK
- SLCyPart__SetCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item, ParameterSet* openParams)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // This method is called to notify the extension that it is now
- // responsible for displaying a new CyberItem. Developers will
- // typically override this method to notify the associated part.
- // Base class releases the old CyberItem (if any) and acquires the new
- // CyberItem. Subsequent calls to GetCyberItem will return this item.
-
- FW_SOM_CALLBACK_TRY
-
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_SetCyberItem(somSelf,ev,item,openParams);
-
- SAFECALL((void),setCyberItem,(ev, somThis->fCallbacks, item, openParams));
-
- // Add the current item to the log.
- CyberItem* parent = kODNULL;
- if (openParams)
- openParams->GetParameter (ev, kCDParentItemKey, (void**) &parent);
- CyberSession* session = somSelf->GetCyberSession (ev);
- if (session)
- session->AddCyberItemToLog (ev, parent, item);
-
- FW_SOM_CALLBACK_ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::CanShowCyberItem
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__CanShowCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // Returns kODTrue if this CyberPart is displaying the specified item.
- // Base class checks whether the item is equal to the value of
- // GetCyberItem(). Note that in some cases developers may wish to use a
- // less stringent test. For example, a web browser may return kODTrue
- // if the item that is passed is a link to a location on that same page
- // that it is displaying. In this case the URL of the item passed in is
- // not the same as the URL of current page, but it is contained in that
- // window.
-
- // This is like an object equality test. x == y is true if x and y
- // are the same object, or if they are similar objects. So, even if the
- // base class returns false (not equal) we still need to test for
- // similarity. Obviously if it returns true then we don't need to
- // test further.
-
- // I think this method is rather badly named.
-
- ODBoolean isSimilar = ODF_FW_OCyberPartExtension_parent_CyberPartExtension_CanShowCyberItem(somSelf,ev,item);
- if (!isSimilar)
- SAFECALL(isSimilar=,canShowCyberItem,(ev, somThis->fCallbacks, item));
-
- return isSimilar;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::ShowCyberItem
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK
- SLCyPart__ShowCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // Tells the part to display the given CyberItem. This differs from
- // SetCyberItem in that the extension has already indicated (through
- // CanShowCyberItem or GetCyberItemWindow) that it is already
- // displaying a cyberitem equal to (or, for example, on the same page
- // as) the item parameter.
- // Developers must not call inherited.
-
- SAFECALL((void),showCyberItem,(ev, somThis->fCallbacks, item));
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::GetCyberItemWindow
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODWindow* SOMLINK
- SLCyPart__GetCyberItemWindow (ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODWindow* window = kODNULL;
- FW_SOM_CALLBACK_TRY
-
- // Returns the ODWindow (if any) in which this CyberPart is displaying
- // the specified item. This is useful e.g. when the client wants to
- // bring an existing window to the front rather than opening a new
- // window. GetCyberItemWindow should use the same algorithm as in
- // CanShowCyberItem method to determine whether an item is displayed in
- // a window.
-
- ODBoolean isShowingSimilar;
- isShowingSimilar = somSelf->CanShowCyberItem (ev, item);
-
- if (isShowingSimilar)
- SAFECALL(window=,getCyberItemWindow,(ev, somThis->fCallbacks, item));
-
- FW_SOM_CALLBACK_ENDTRY
- return window;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::IsCyberItemSelected
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__IsCyberItemSelected(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean isAnySelected = false;
- FW_SOM_CALLBACK_TRY
-
- SAFECALL(isAnySelected=,isCyberItemSelected,(ev, somThis->fCallbacks, frame));
-
- FW_SOM_CALLBACK_ENDTRY
- return isAnySelected;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::AcquireSelectedCyberItems
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK
- SLCyPart__AcquireSelectedCyberItems(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame, CyberItemList* cyberItems)
- {
- // XXX should change this to pass an STL list?
- // Note: If I do it has to be exception-safe.
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- FW_SOM_CALLBACK_TRY
-
- SAFECALL((void),acquireSelectedCyberItems,(ev, somThis->fCallbacks, frame, cyberItems));
-
- FW_SOM_CALLBACK_ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::IsURLSelected
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__IsURLSelected(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean isSelected = FALSE;
- FW_SOM_CALLBACK_TRY
-
- SAFECALL(isSelected=,isURLSelected,(ev, somThis->fCallbacks, frame));
-
- FW_SOM_CALLBACK_ENDTRY
- return isSelected;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::GetSelectedURL
- //-----------------------------------------------------------------------------
-
- SOM_Scope char* SOMLINK
- SLCyPart__GetSelectedURL(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- char* urld = kODNULL;
- FW_SOM_CALLBACK_TRY
-
- FW_CString surl;
- SAFECALL((void),getSelectedURL,(ev, somThis->fCallbacks, frame, surl));
-
- // Note: this code has been arranged so it does not throw any C++ exceptions.
- FW_ByteCount size = surl.GetByteLength();
- if (size) {
- urld = (char*) ::MMAllocate (size + 1);
- if (urld) {
- const char* privates = surl.RevealBuffer();
- memcpy (urld, privates, size);
- urld[size] = 0;
- }
- else
- FW_SetException (ev, kODErrOutOfMemory);
- }
-
- FW_SOM_CALLBACK_ENDTRY
-
- return urld;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::HandleCommand
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__HandleCommand(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- long commandSuite,
- long commandID,
- ODFrame* frame,
- void* commandData)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean wasHandled = false;
- FW_SOM_CALLBACK_TRY
-
- // Intended as an extensibility mechanism for Cyber parts where clients
- // can send commands to the part/extension. The function result
- // indicates whether or not the command was handled.
- // Cyberdog defines some commands in Cyberdog.h. The commandCreator
- // associated with Cyberdogs commands is kCyberdogCreator.
- // Developers may call inherited.
-
- // mlanett 4/18/96 see comment for OpenCyberItem. Removed call to inherited. See FW_CCyberdogHelper::HandleCyberCommand.
- ODBoolean callInherited = false;
-
- SAFECALL(wasHandled=,handleCommand,(ev, somThis->fCallbacks, commandSuite, commandID, frame, commandData));
- if (callInherited)
- wasHandled |= ODF_FW_OCyberPartExtension_parent_CyberPartExtension_HandleCommand (somSelf,ev,commandSuite,commandID,frame,commandData);
-
- FW_SOM_CALLBACK_ENDTRY
- return wasHandled;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::SetCallbacks
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK
- SLCyPart__SetCallbacks(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- FW_HCyberPartInterfaceCallbacks callbacks)
- {
- // Note: No exception handling here.
- FW_UNUSED(ev);
-
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- somThis->fCallbacks = callbacks;
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::DefaultOpenCyberItem
- //-----------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK SLCyPart__DefaultOpenCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- CyberItem* item,
- ODPart* openerPart,
- ParameterSet* openParams)
- {
- FW_SOM_CALLBACK_TRY
-
- // This method enabled us to call "inherited" OpenCyberItem from the C++ class.
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem(somSelf,ev,item,openerPart,openParams);
-
- FW_SOM_CALLBACK_ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // SLCyPart::DefaultHandleCommand
- //-----------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK SLCyPart__DefaultHandleCommand(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- long commandCreator,
- long commandID,
- ODFrame* frame,
- void* commandData)
- {
- ODBoolean handled = FALSE;
- FW_SOM_CALLBACK_TRY
-
- // This method enabled us to call "inherited" HandleCommand from the C++ class.
- handled = ODF_FW_OCyberPartExtension_parent_CyberPartExtension_HandleCommand (somSelf,ev,commandCreator,commandID,frame,commandData);
-
- FW_SOM_CALLBACK_ENDTRY
- return handled;
- }
-
-